$(function () {
  //Language button switch show hide
  $(document).ready(function () {
    $(".language-toggle").click(function () {
      $(".language-list").toggle();
    });
  });

  // 首页 轮播
  if ($(".homeContent_1 .slide").length > 0) {
    var mySwiper = new Swiper(".swiper-container", {
      loop: true,
      slidesPerView: "auto",
      autoplay: true,
      spaceBetween: 30,
      centeredSlides: true,
      pagination: {
        el: ".swiper-pagination",
      },
    });
  }

  //首页榜单tab切换
  $(".homeContent_5 .tabBar")
    .find("div")
    .on("click", function () {
      let index = $(this).index();
      $(this).addClass("current").siblings().removeClass("current");
      $(this).parents(".homeContent_5").find(".list > ul").eq(index).show().siblings().hide();
    });

  //排行榜页榜单tab切换
  $(".rankContent_2 .tabBar")
    .find("div")
    .on("click", function () {
      let index = $(this).index();
      $(this).addClass("current").siblings().removeClass("current");
      $(this).parents(".rankContent_2").find(".list > ul").eq(index).show().siblings().hide();
    });

  /* //助手包切换
  $(document).on("click", "#safe_down_id", function () {
    if ($(this).is(":checked") == true) {
      //选中触发事件
      $("#down-btn p").html(pageConfig.hpdown_button_name);
      if (false) {
        // if (pageConfig.hpdown_id == 33) {
        $("#down-btn").attr("href", "javascript: void(0);");
        $("#down-btn").attr("onclick", "publish_cpa_log()");
      } else {
        $("#down-btn").attr("href", pageConfig.hpdown_url);
        $("#down-btn").attr("onclick", "publish_hp_new_log()");
      }
      // $(".down_and_btn").parent('.mgd_down_box').css('display','none')
      // $(".down_safe_btn").parent('.mgd_down_box').css('display','block')
    } else {
      //取消选中触发事件
      $("#down-btn p").html(`<i class="icon"></i>安卓下载(${pageConfig.soft_size})`);
      $("#down-btn").attr("href", pageConfig.down_url);
      $("#down-btn").attr("onclick", "push_down_log()");
      // $(".down_and_btn").parent('.mgd_down_box').css('display','block')
      // $(".down_safe_btn").parent('.mgd_down_box').css('display','none')
    }
  }); */

  // 截图滚动
  if ($(".show_img").length > 0) {
    var img_swiper = new Swiper(".gameImg", {
      slidesOffsetBefore: 0,
      slidesOffsetAfter: 0,
      slidesPerView: "auto",
      spaceBetween: 10,
      freeMode: true,
    });
    let img = new Image();
    img.src = $(".gameImg .swiper-slide img").attr("src");
    img.onload = function () {
      if (img.width > img.height) {
        $(".gameImg .swiper-slide").height(160);
        $(".gameImg .swiper-slide img").height(160);
      }
    };
  }

  // 锚点
  $(".gdContent_3 .tabBar div").on("click", function () {
    $(this).addClass("current").siblings("div").removeClass("current");
    var h1 = $(".wrap").find(".gdContent_4").length > 0 ? $(".gdContent_4").offset().top : 0;
    var h2 = $(".wrap").find(".gdContent_7").length > 0 ? $(".gdContent_7").offset().top : 0;
    var h3 = $(".wrap").find(".mgd_tag_recom_box").length > 0 ? $(".mgd_tag_recom_box").offset().top : 0;
    var h4 = $(".wrap").find(".otherGame").length > 0 ? $(".otherGame").offset().top : 0;
    if ($(this).hasClass("intro")) {
      $("html,body").animate({ scrollTop: h1 - 60 }, 800);
    } else if ($(this).hasClass("recommend")) {
      $("html,body").animate({ scrollTop: h2 - 60 }, 800);
    } else if ($(this).hasClass("related")) {
      $("html,body").animate({ scrollTop: (h3 == 0 ? h4 : h3) - 60 }, 800);
    }
  });

  // 详情相关推荐 tab切换
  $(".mgd_tag_recom_box .tab_menu")
    .find("span")
    .on("click", function () {
      let index = $(this).index();
      $(this).addClass("checked").siblings().removeClass("checked");
      $(this).parents(".mgd_tag_recom_box").find(".tab_cont > div").eq(index).show().siblings().hide();
    });

  // 悬浮下载按钮
  if ($(".downbtn").length > 0) {
    topfix = $(".downbtn").position().top;
    $(window).scroll(function () {
      var height = $(window).scrollTop();
      if (height > topfix) {
        $(".m-hover-game-box").show();
      } else {
        $(".m-hover-game-box").hide();
      }
    });
  }
});

$(window).load(function () {
  // 首页 热门专题
  if ($(".gallery-top").length > 0 && $(".gallery-thumbs").length > 0) {
    $(".gallery-top .swiper-slide-active").removeClass("swiper-slide-active");
    var galleryThumbs1 = new Swiper(".gallery-thumbs", {
      slidesPerView: 1,
      freeMode: false,
      watchSlidesVisibility: true,
      watchSlidesProgress: true,
    });
    var galleryTop1 = new Swiper(".gallery-top", {
      slidesPerView: "auto",
      autoplay: true,
      loop: true,
      spaceBetween: 10,
      thumbs: {
        swiper: galleryThumbs1,
      },
    });
  }
});

//专题详情
$(function () {
  $(".ztDetailContent_2 .desc .look").on("click", function () {
    $("#popupsBox").removeClass("hide");
  });
  $(".ztDetailPopups .popupsClose").on("click", function () {
    $("#popupsBox").addClass("hide");
  });
  //滚动字幕
  const h = $(".ztDetailContent_2 .desc .cover p").height() - 46;
  let s = 0;
  let timer = setInterval(() => {
    if (s < h) {
      $(".ztDetailContent_2 .desc .cover p").css("top", `-${++s}px`);
    } else {
      s = 0;
    }
  }, 100);

  $(".ztDetailPopups .close").on("click", function () {
    $("#popupsBox").addClass("hide");
  });
});

/* function closeJd() {
  document.getElementById("jd_dom").style.display = "none";
} */
